package com.example.memohehang.controller;


import com.example.memohehang.common.R;
import com.example.memohehang.service.OssUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadController
{
    @Autowired
    private OssUploadService ossUploadService;

    @PostMapping("/upload")
    public ResponseEntity<R> uploadImg(MultipartFile img)
    {
        HttpHeaders headers = new HttpHeaders();
        headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
        headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "*");
        R r = ossUploadService.uploadImg(img);
        return ResponseEntity.ok()
                .headers(headers)
                .body(r);
    }
}